//
//  MusicViewController.m
//  EDPS
//
//  Created by dllo on 15/12/1.
//  Copyright © 2015年 张维扬. All rights reserved.
//

#import "MusicViewController.h"
#import "ZWY_NetHandle.h"
#import "MusicTableViewCell.h"
#import "SingleModel.h"
#import "MusicDetailViewController.h"

@interface MusicViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,retain) UITableView *tableView;
@property (nonatomic,retain) NSMutableArray *DataArray;
@property (nonatomic,copy) NSString *modelStr;
@property (nonatomic,assign) BOOL isOpen;

@end

@implementation MusicViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"我的音乐";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:self action:@selector(turnBack)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
    self.DataArray = [NSMutableArray array];
    [self creatData];
    [self creatView];
    
}
- (void)creatView
{
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.DataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MusicTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"deq"];
    if (cell == nil)
    {
        cell = [[MusicTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"deq"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    SingleModel *model = [self.DataArray objectAtIndex:indexPath.row];
    cell.singleModel = model;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 110;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SingleModel *model = [self.DataArray objectAtIndex:indexPath.row];
    MusicDetailViewController *detail = [MusicDetailViewController sharePlayerViewController];
    detail.model = model;
    detail.dataArr = self.DataArray;
    detail.indexRow = indexPath.row;
    [self.navigationController pushViewController:detail animated:YES];
}
- (void)creatData
{
    NSString *url = @"http://mobile.ximalaya.com/mobile/others/ca/album/track/321797/true/1/30?device=iPhone";
    [ZWY_NetHandle getURL:url Cookie:nil parameter:nil result:^(id result)
    {
        NSMutableDictionary *dictionary = result;
        NSMutableDictionary *dictionary2 = [dictionary objectForKey:@"tracks"];
        NSMutableArray *array = [dictionary2 objectForKey:@"list"];
        for (NSMutableDictionary *dic in array)
        {
            SingleModel *singleModel = [[SingleModel alloc] init];
            [singleModel setValuesForKeysWithDictionary:dic];
            [self.DataArray addObject:singleModel];
        }
        [self.tableView reloadData];
    }];
}
- (void)turnBack
{
    [self.navigationController popViewControllerAnimated:YES];
}


@end